﻿using DevExpress.XtraGrid.Demos.util;
using Luna小店.DTO;
using Luna小店.UC.门店下单.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Luna小店.UC.款式管理
{
    public partial class Frm款式维护记录一览 : DevExpress.XtraEditors.XtraForm
    {
        private List<款式维护记录> dtos款式维护记录 = new List<款式维护记录>();
        public Frm款式维护记录一览()
        {
            InitializeComponent();
            this.dtos款式维护记录 = FunctionHelper.JsonDeserialization<List<款式维护记录>>(RestCall.httpGetMethod(URL.接口url + "/style/findStyleIndexAll"));
            this.gridControl款式维护记录一览.DataSource = this.dtos款式维护记录;
        }

        private void gridView款式维护记录一览_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            new Frm款式维护预览(FunctionHelper.GetgridViewValue(this.gridView款式维护记录一览,e.RowHandle, "styleId")).ShowDialog();
        }

        private void simpleButton新增_Click(object sender, EventArgs e)
        {
            //new Frm款式维护预览().ShowDialog();
            new Frm款式维护记录新建().ShowDialog();
        }

        private void gridView款式维护记录一览_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.Column == this.colfitImport)
            {
                foreach (款式维护记录 dto in this.dtos款式维护记录)
                {
                    if (dto.id.Equals(FunctionHelper.GetgridViewValue(this.gridView款式维护记录一览, e.RowHandle, "id")))
                    {
                        dto.fitImport = Convert.ToBoolean(e.Value);
                        RestCall.PostHttp(URL.接口url + "/style/saveStyleIndex", FunctionHelper.JsonSerialization(dto));
                        break;
                    }
                }
            }
            else if (e.Column == this.colstyleImport)
            {
                foreach (款式维护记录 dto in this.dtos款式维护记录)
                {
                    if (dto.id.Equals(FunctionHelper.GetgridViewValue(this.gridView款式维护记录一览, e.RowHandle, "id")))
                    {
                        dto.styleImport = Convert.ToBoolean(e.Value);
                        RestCall.PostHttp(URL.接口url + "/style/saveStyleIndex", FunctionHelper.JsonSerialization(dto));
                        break;
                    }
                }
            }
        }
    }
}
